package com.example.tnot.Teacher.CoursePart.Container.AddCourse;

import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.tnot.R;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;
import com.example.tnot.Teacher.CoursePart.Container.AddCourse.Adapter.SelectTermAdapter;
import com.example.tnot.Teacher.CoursePart.Container.AddCourse.ItemBean.Term;

import java.util.ArrayList;
import java.util.List;

public class SelectTermFragment extends BaseBackFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private String mParam1;
    private String mParam2;
    View view;
    ImageView ib_back;
    TextView tv_finish;
    TextView tv_term;
    RecyclerView rv_SelectTerm;
    private List<Term> terms;

    public SelectTermFragment() {
    }

    public static SelectTermFragment newInstance(String param1, String param2) {
        SelectTermFragment fragment = new SelectTermFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.course_select_term_fragment, container, false);
        terms = new ArrayList<>();
        InitData();
        rv_SelectTerm = view.findViewById(R.id.rv_SelectTerm);
        rv_SelectTerm.setLayoutManager(new LinearLayoutManager(getActivity()));
        SelectTermAdapter adapter = new SelectTermAdapter(terms);
        rv_SelectTerm.setAdapter(adapter);


        ib_back = view.findViewById(R.id.back);
        ib_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                handleBackPressed();
            }
        });
        tv_finish = view.findViewById(R.id.tv_finish);
        tv_finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                handleBackPressed();
            }
        });

        return view;
    }

    private void InitData() {
        terms.add(new Term("2023-2024-1"));
        terms.add(new Term("2023-2024-2"));
        terms.add(new Term("2024-2025-1"));
        terms.add(new Term("2024-2025-2"));
    }
}